﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using Assist;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Architecture;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using YJKRoomInspection.FireAreOutLineAppend;
using YJKRoomInspection.Model;
using YJKRoomInspection.Properties;
using YJKRoomInspection.Utiltiy;
using YArchitech.Controls;
using YArchitech.LIB;
using YJKRevitFamilyDataBase;
using YJKRevitKernel.FormUtility.ModelessFormControlSuite.ModelLayer;
using YJKInspectModelFunc;
using YJKInspectModelFunc.ControlLayer;
using YJKInspectModelFunc.ModelLayer;

namespace YJKRoomInspection.ShowDataForm
{
    public partial class FireProofGradeForm : System.Windows.Forms.Form, YJKRevitKernel.FormUtility.ModelessFormControlSuite.ModelLayer.IModelessFormNoneSwitch
	{
		public List<AdapteDoorResultPakcer> m_lstAdapteDoorPackers
		{
			get
			{
				return this.lstAdapteDoorPackers;
			}
		}

		public IWin32Window RevitHandle
		{
			get
			{
				return this.m_revitHandle;
			}
			private set
			{
				this.m_revitHandle = value;
			}
		}

		public FireProofGradeForm(IWin32Window inputHandle, List<ICloseCurveAnalays> input, ExternalCommandData cmdData)
		{
			this.uidoc = cmdData.Application.ActiveUIDocument;
			this.document = this.uidoc.Document;
			this.m_cmdData = cmdData;
			this.m_revitHandle = inputHandle;
			foreach (Element element in new FilteredElementCollector(this.document).OfClass(typeof(ViewPlan)).WhereElementIsNotElementType())
			{
				ViewPlan item = element as ViewPlan;
				this.lstviewList.Add(item);
			}
			this.lstAdapteDoorPackers = this.AdapteOutLineResule(input);
			this.InitializeComponent();
			this.BindData(this.lstAdapteDoorPackers);
			this.lstIsNotLinkDoor = this.GetIsNotLinkDoor();
			this.lstDoorAndWindow = this.GetDoorAndWindow();
		}

		[DllImport("user32.dll", EntryPoint = "SendMessageA")]
		public static extern int SendMessage(IntPtr hwnd, int wMsg, IntPtr wParam, IntPtr lParam);

		private void FireProofGradeForm_MouseLeave(object sender, EventArgs e)
		{
			if (!base.ClientRectangle.Contains(base.PointToClient(Cursor.Position)))
			{
				int wMsg = 7;
				FireProofGradeForm.SendMessage(SelectFloorForm._hWndSelectFloorForm.Handle, wMsg, IntPtr.Zero, IntPtr.Zero);
				return;
			}
			base.Focus();
		}

		private void FireProofGradeForm_Load(object sender, EventArgs e)
		{
			//base.Icon = Resource.YArchitechIcon;
			if (!string.IsNullOrEmpty(this.strFormCaption))
			{
				this.Text = this.strFormCaption;
			}
			this.dataGridView3.AutoGenerateColumns = false;
			this.dataGridView3.EnableHeadersVisualStyles = true;
			this.SetRowStyle();
			this.InitFamilyLibDoorWins();
		}

		private List<AdapteDoorResultPakcer> AdapteOutLineResule(List<ICloseCurveAnalays> AllRoomPackers)
		{
			string b = null;
			double num = 0.0;
			List<AdapteDoorResultPakcer> collection = new List<AdapteDoorResultPakcer>();
			foreach (ViewPlan viewPlan in this.lstviewList)
			{
				Parameter parameter = viewPlan.get_Parameter(BuiltInParameter.VIEW_TYPE_SCHEDULES);
				if (parameter != null && parameter.AsString().Contains("防火分区面积"))
				{
					Level genLevel = viewPlan.GenLevel;
					using (List<Level>.Enumerator enumerator2 = StaticRescource.m_SelectLevels.GetEnumerator())
					{
						while (enumerator2.MoveNext())
						{
							if (enumerator2.Current.Id == genLevel.Id)
							{
								this.lstUseViewPlan.Add(viewPlan);
								break;
							}
						}
					}
				}
			}
			collection = BaseManger.GetCheckResults(this.lstUseViewPlan);
			InsertDoor insertDoor = new InsertDoor();
			for (int i = 0; i < AllRoomPackers.Count; i++)
			{
				Element thisElement = AllRoomPackers[i].GetThisElement();
				if (thisElement is Room)
				{
					b = (thisElement as Room).Name;
					num = (thisElement as Room).Area;
				}
				else if (thisElement is FilledRegion)
				{
					b = (thisElement as FilledRegion).Name;
					num = YJKRoomInspection.Utiltiy.Utility.ChangeAreaByUnit((thisElement as FilledRegion).get_Parameter(BuiltInParameter.HOST_AREA_COMPUTED).AsDouble());
				}
				insertDoor = InsertDataToRoom.ReadDoorElement<InsertDoor>(thisElement, YJKRoomInspection.Properties.Resources.DoorGuid);
				if (insertDoor.m_FrontRoomName != null && insertDoor.m_FrontRoomArea != 0.0 && insertDoor.m_FrontRoomArea == num && insertDoor.m_FrontRoomName == b)
				{
					AllRoomPackers.Remove(AllRoomPackers[i]);
					i--;
				}
			}
			foreach (ICloseCurveAnalays closeCurveAnalays in AllRoomPackers)
			{
				foreach (BaseDoorPacker baseDoorPacker in closeCurveAnalays.GetAllDoors())
				{
					FrontRoomDoorPacker frontRoomDoorPacker = baseDoorPacker as FrontRoomDoorPacker;
					if (!frontRoomDoorPacker.IsRight)
					{
						this.lstAdapteDoorPackers.Add(new AdapteDoorResultPakcer(frontRoomDoorPacker, closeCurveAnalays));
					}
				}
			}
			this.lstAdapteDoorPackers.AddRange(collection);
			return this.lstAdapteDoorPackers;
		}

		private void BindData(List<AdapteDoorResultPakcer> lstAdapteDoorPackers)
		{
			this.BindFrontRoomDoorData(lstAdapteDoorPackers);
			this.BindWindowDoorData(lstAdapteDoorPackers);
			this.BindWallDoorData(lstAdapteDoorPackers);
		}

		private void BindFrontRoomDoorData(List<AdapteDoorResultPakcer> lstAdapteDoorPackers)
		{
			int num = 0;
			this.m_RoomTable = new DataTable();
			this.m_RoomTable.Columns.Add("FloorName", typeof(string));
			this.m_RoomTable.Columns.Add("DoorName", typeof(string));
			this.lstUseDoorPackers.Clear();
			this.m_dicFrontRoomDoor.Clear();
			for (int i = 0; i < lstAdapteDoorPackers.Count; i++)
			{
				if (lstAdapteDoorPackers[i].ThisType == EleType.eFrontRoomDoor)
				{
					this.lstUseDoorPackers.Add(lstAdapteDoorPackers[i]);
				}
			}
			Dictionary<int, Level> m_Level_index = new Dictionary<int, Level>();
			foreach (AdapteDoorResultPakcer adapteDoorResultPakcer in this.lstUseDoorPackers)
			{
				if (!this.m_dicFrontRoomDoor.Keys.Contains(adapteDoorResultPakcer.UseLevel.Id.IntegerValue))
				{
					this.m_dicFrontRoomDoor.Add(adapteDoorResultPakcer.UseLevel.Id.IntegerValue, new List<AdapteDoorResultPakcer>());
					m_Level_index.Add(adapteDoorResultPakcer.UseLevel.Id.IntegerValue, adapteDoorResultPakcer.UseLevel);
				}
				this.m_dicFrontRoomDoor[adapteDoorResultPakcer.UseLevel.Id.IntegerValue].Add(adapteDoorResultPakcer);
			}
			this.m_dicFrontRoomDoor = (from k in this.m_dicFrontRoomDoor
			orderby m_Level_index[k.Key].Elevation
			select k).ToDictionary((KeyValuePair<int, List<AdapteDoorResultPakcer>> k) => k.Key, (KeyValuePair<int, List<AdapteDoorResultPakcer>> k) => k.Value);
			foreach (KeyValuePair<int, List<AdapteDoorResultPakcer>> keyValuePair in this.m_dicFrontRoomDoor)
			{
				foreach (AdapteDoorResultPakcer adapteDoorResultPakcer2 in keyValuePair.Value)
				{
					string name = adapteDoorResultPakcer2.UseLevel.Name;
					string name2 = adapteDoorResultPakcer2.ThisElement.Name;
					this.m_RoomTable.Rows.Add(new string[]
					{
						name,
						name2
					});
					if (adapteDoorResultPakcer2.UseRevitLinkInstance == null)
					{
						num++;
						if (!this.m_RowRoomId.Keys.Contains(num))
						{
							this.m_RowRoomId.Add(num, new List<int>());
						}
						this.m_RowRoomId[num].Add(adapteDoorResultPakcer2.ThisElement.Id.IntegerValue);
					}
				}
			}
			this.bindingSource1.DataSource = this.m_RoomTable;
		}

		private void BindWindowDoorData(List<AdapteDoorResultPakcer> lstAdapteDoorPackers)
		{
			DataTable dataTable = new DataTable();
			int num = 0;
			dataTable.Columns.Add("FloorName", typeof(string));
			dataTable.Columns.Add("DoorName", typeof(string));
			this.lstUseDoorPackers.Clear();
			this.m_dicWindowDoor.Clear();
			for (int i = 0; i < lstAdapteDoorPackers.Count; i++)
			{
				if (lstAdapteDoorPackers[i].ThisType == EleType.eDoor || lstAdapteDoorPackers[i].ThisType == EleType.eDoorRolling || lstAdapteDoorPackers[i].ThisType == EleType.eWindow)
				{
					this.lstUseDoorPackers.Add(lstAdapteDoorPackers[i]);
				}
			}
			Dictionary<int, Level> m_Level_index = new Dictionary<int, Level>();
			foreach (AdapteDoorResultPakcer adapteDoorResultPakcer in this.lstUseDoorPackers)
			{
				if (!this.m_dicWindowDoor.Keys.Contains(adapteDoorResultPakcer.UseLevel.Id.IntegerValue))
				{
					this.m_dicWindowDoor.Add(adapteDoorResultPakcer.UseLevel.Id.IntegerValue, new List<AdapteDoorResultPakcer>());
					m_Level_index.Add(adapteDoorResultPakcer.UseLevel.Id.IntegerValue, adapteDoorResultPakcer.UseLevel);
				}
				this.m_dicWindowDoor[adapteDoorResultPakcer.UseLevel.Id.IntegerValue].Add(adapteDoorResultPakcer);
			}
			this.m_dicWindowDoor = (from k in this.m_dicWindowDoor
			orderby m_Level_index[k.Key].Elevation
			select k).ToDictionary((KeyValuePair<int, List<AdapteDoorResultPakcer>> k) => k.Key, (KeyValuePair<int, List<AdapteDoorResultPakcer>> k) => k.Value);
			foreach (KeyValuePair<int, List<AdapteDoorResultPakcer>> keyValuePair in this.m_dicWindowDoor)
			{
				foreach (AdapteDoorResultPakcer adapteDoorResultPakcer2 in keyValuePair.Value)
				{
					string name = adapteDoorResultPakcer2.UseLevel.Name;
					string name2 = adapteDoorResultPakcer2.ThisElement.Name;
					dataTable.Rows.Add(new string[]
					{
						name,
						name2
					});
					if (!adapteDoorResultPakcer2.BIsLinkElement)
					{
						num++;
						if (!this.m_RowWinId.Keys.Contains(num))
						{
							this.m_RowWinId.Add(num, new List<int>());
						}
						this.m_RowWinId[num].Add(adapteDoorResultPakcer2.ThisElement.Id.IntegerValue);
					}
				}
			}
			this.bindingSource2.DataSource = dataTable;
		}

		private void BindWallDoorData(List<AdapteDoorResultPakcer> lstAdapteDoorPackers)
		{
			DataTable dataTable = new DataTable();
			int num = 0;
			dataTable.Columns.Add("FloorName", typeof(string));
			dataTable.Columns.Add("DoorName", typeof(string));
			this.lstUseDoorPackers.Clear();
			this.m_dicWallDoor.Clear();
			for (int i = 0; i < lstAdapteDoorPackers.Count; i++)
			{
				if (lstAdapteDoorPackers[i].ThisType == EleType.eWall)
				{
					this.lstUseDoorPackers.Add(lstAdapteDoorPackers[i]);
				}
			}
			Dictionary<int, Level> m_Level_index = new Dictionary<int, Level>();
			foreach (AdapteDoorResultPakcer adapteDoorResultPakcer in this.lstUseDoorPackers)
			{
				if (!this.m_dicWallDoor.Keys.Contains(adapteDoorResultPakcer.UseLevel.Id.IntegerValue))
				{
					this.m_dicWallDoor.Add(adapteDoorResultPakcer.UseLevel.Id.IntegerValue, new List<AdapteDoorResultPakcer>());
					m_Level_index.Add(adapteDoorResultPakcer.UseLevel.Id.IntegerValue, adapteDoorResultPakcer.UseLevel);
				}
				this.m_dicWallDoor[adapteDoorResultPakcer.UseLevel.Id.IntegerValue].Add(adapteDoorResultPakcer);
			}
			this.m_dicWallDoor = (from k in this.m_dicWallDoor
			orderby m_Level_index[k.Key].Elevation
			select k).ToDictionary((KeyValuePair<int, List<AdapteDoorResultPakcer>> k) => k.Key, (KeyValuePair<int, List<AdapteDoorResultPakcer>> k) => k.Value);
			foreach (KeyValuePair<int, List<AdapteDoorResultPakcer>> keyValuePair in this.m_dicWallDoor)
			{
				foreach (AdapteDoorResultPakcer adapteDoorResultPakcer2 in keyValuePair.Value)
				{
					string name = adapteDoorResultPakcer2.UseLevel.Name;
					string name2 = adapteDoorResultPakcer2.ThisElement.Name;
					dataTable.Rows.Add(new string[]
					{
						name,
						name2
					});
					if (!adapteDoorResultPakcer2.BIsLinkElement)
					{
						num++;
						if (!this.m_RowWallId.Keys.Contains(num))
						{
							this.m_RowWallId.Add(num, new List<int>());
						}
						this.m_RowWallId[num].Add(adapteDoorResultPakcer2.ThisElement.Id.IntegerValue);
					}
				}
			}
			this.bindingSource3.DataSource = dataTable;
		}

		private void SetRowStyle()
		{
			this.m_RowStyleAlternate = new DataGridViewCellStyle();
			this.m_RowStyleAlternate.BackColor = System.Drawing.Color.Azure;
			this.m_RowStyleAlternate.SelectionBackColor = System.Drawing.Color.LightGray;
		}

		private void ReplaceFamilyInstance()
		{
			List<string> list = new List<string>
			{
				this.m_strDoorClassAFiName,
				this.m_strDoorSuperFiName,
				this.m_strWindowFiName
			};
			List<string> list2 = new List<string>
			{
				YJKRoomInspection.Properties.Resources.Str_FamilyDbKindName_FireDoor,
				YJKRoomInspection.Properties.Resources.Str_FamilyDbKindName_FireRoolDoor,
				YJKRoomInspection.Properties.Resources.Str_FamilyDbKindName_FireWindow
			};
			try
			{
				for (int i = 0; i < list.Count; i++)
				{
					if (!(list[i] == ""))
					{
						this.useKindAndNames.Add(list2[i], list[i]);
					}
				}
			}
			catch (Exception)
			{
				YJKMessageBox.Show("已替换完成，请勿重复替换相同构件");
			}
		}

		private void ReplaceRoomDoorAction()
		{
			List<string> list = new List<string>
			{
				this.m_strDoorClassAFiName,
				this.m_strDoorSuperFiName
			};
			List<string> list2 = new List<string>
			{
				YJKRoomInspection.Properties.Resources.Str_FamilyDbKindName_FireDoor,
				YJKRoomInspection.Properties.Resources.Str_FamilyDbKindName_FireRoolDoor
			};
			try
			{
				for (int i = 0; i < list.Count; i++)
				{
					if (!(list[i] == ""))
					{
						this.useKindAndNames.Add(list2[i], list[i]);
					}
				}
			}
			catch (Exception)
			{
				YJKMessageBox.Show("已替换完成，请勿重复替换相同构件");
			}
		}

		private List<AdapteDoorResultPakcer> GetIsNotLinkDoor()
		{
			List<AdapteDoorResultPakcer> list = new List<AdapteDoorResultPakcer>();
			foreach (KeyValuePair<int, List<AdapteDoorResultPakcer>> keyValuePair in this.m_dicFrontRoomDoor)
			{
				foreach (AdapteDoorResultPakcer adapteDoorResultPakcer in keyValuePair.Value)
				{
					if (adapteDoorResultPakcer.UseRevitLinkInstance == null)
					{
						list.Add(adapteDoorResultPakcer);
					}
				}
			}
			return list;
		}

		private List<AdapteDoorResultPakcer> GetDoorAndWindow()
		{
			List<AdapteDoorResultPakcer> list = new List<AdapteDoorResultPakcer>();
			foreach (AdapteDoorResultPakcer adapteDoorResultPakcer in this.lstAdapteDoorPackers)
			{
				if (!adapteDoorResultPakcer.BIsLinkElement && (adapteDoorResultPakcer.ThisType == EleType.eDoor || adapteDoorResultPakcer.ThisType == EleType.eDoorRolling || adapteDoorResultPakcer.ThisType == EleType.eWindow))
				{
					list.Add(adapteDoorResultPakcer);
				}
			}
			return list;
		}

		private List<AdapteDoorResultPakcer> GetWall(List<AdapteDoorResultPakcer> OldDoorsResult)
		{
			List<AdapteDoorResultPakcer> list = new List<AdapteDoorResultPakcer>();
			foreach (AdapteDoorResultPakcer adapteDoorResultPakcer in OldDoorsResult)
			{
				if (adapteDoorResultPakcer.ThisType == EleType.eWall)
				{
					list.Add(adapteDoorResultPakcer);
				}
			}
			return list;
		}

		private void dgvDataTable_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
		{
			if (e.ColumnIndex == this.dataGridView3.Columns["FloorName"].Index)
			{
				DataGridViewRow dataGridViewRow = this.dataGridView3.Rows[e.RowIndex];
				dataGridViewRow.HeaderCell.Value = Convert.ToString(e.RowIndex + 1);
				if (e.RowIndex == 0)
				{
					dataGridViewRow.DefaultCellStyle = this.m_RowStyleAlternate;
					return;
				}
				if (dataGridViewRow.Cells[e.ColumnIndex].Value != DBNull.Value && dataGridViewRow.Cells[e.ColumnIndex].Value != null && dataGridViewRow.Cells[e.ColumnIndex].Value.ToString() == this.dataGridView3.Rows[e.RowIndex - 1].Cells[e.ColumnIndex].Value.ToString())
				{
					dataGridViewRow.DefaultCellStyle = this.dataGridView3.Rows[e.RowIndex - 1].DefaultCellStyle;
					dataGridViewRow.Cells[e.ColumnIndex].Style.ForeColor = dataGridViewRow.DefaultCellStyle.BackColor;
					return;
				}
				if (this.dataGridView3.Rows[e.RowIndex - 1].DefaultCellStyle == this.m_RowStyleAlternate)
				{
					dataGridViewRow.DefaultCellStyle = this.m_RowStyleAlternate;
				}
			}
		}

		private void dgvDataTable1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
		{
			if (e.ColumnIndex == this.dataGridView1.Columns["WinFloorName"].Index)
			{
				DataGridViewRow dataGridViewRow = this.dataGridView1.Rows[e.RowIndex];
				dataGridViewRow.HeaderCell.Value = Convert.ToString(e.RowIndex + 1);
				if (e.RowIndex == 0)
				{
					dataGridViewRow.DefaultCellStyle = this.m_RowStyleAlternate;
					return;
				}
				if (dataGridViewRow.Cells[e.ColumnIndex].Value != DBNull.Value && dataGridViewRow.Cells[e.ColumnIndex].Value != null && dataGridViewRow.Cells[e.ColumnIndex].Value.ToString() == this.dataGridView1.Rows[e.RowIndex - 1].Cells[e.ColumnIndex].Value.ToString())
				{
					dataGridViewRow.DefaultCellStyle = this.dataGridView1.Rows[e.RowIndex - 1].DefaultCellStyle;
					dataGridViewRow.Cells[e.ColumnIndex].Style.ForeColor = dataGridViewRow.DefaultCellStyle.BackColor;
					return;
				}
				if (this.dataGridView1.Rows[e.RowIndex - 1].DefaultCellStyle == this.m_RowStyleAlternate)
				{
					dataGridViewRow.DefaultCellStyle = this.m_RowStyleAlternate;
				}
			}
		}

		private void dgvDataTable2_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
		{
			if (e.ColumnIndex == this.dataGridView2.Columns["WallFloorName"].Index)
			{
				DataGridViewRow dataGridViewRow = this.dataGridView2.Rows[e.RowIndex];
				dataGridViewRow.HeaderCell.Value = Convert.ToString(e.RowIndex + 1);
				if (e.RowIndex == 0)
				{
					dataGridViewRow.DefaultCellStyle = this.m_RowStyleAlternate;
					return;
				}
				if (dataGridViewRow.Cells[e.ColumnIndex].Value != DBNull.Value && dataGridViewRow.Cells[e.ColumnIndex].Value != null && dataGridViewRow.Cells[e.ColumnIndex].Value.ToString() == this.dataGridView2.Rows[e.RowIndex - 1].Cells[e.ColumnIndex].Value.ToString())
				{
					dataGridViewRow.DefaultCellStyle = this.dataGridView2.Rows[e.RowIndex - 1].DefaultCellStyle;
					dataGridViewRow.Cells[e.ColumnIndex].Style.ForeColor = dataGridViewRow.DefaultCellStyle.BackColor;
					return;
				}
				if (this.dataGridView2.Rows[e.RowIndex - 1].DefaultCellStyle == this.m_RowStyleAlternate)
				{
					dataGridViewRow.DefaultCellStyle = this.m_RowStyleAlternate;
				}
			}
		}

		private void TrustBtn_Click(object sender, EventArgs e)
		{
			this.m_strReplaceOrder = "TrustAction";
			this.m_bIfContinue = true;
			this.m_bIfBreak = false;
			this.m_bIfManuEsc = false;
			this.SendEscMessageToRevitAndClearSelect();
			this.m_useBeforeCotinueMethod = new FireProofGradeForm.BeforeContinueMethod(this.TrustAction);
			this.bindingSource1.DataSource = this.m_RoomTable;
			this.dataGridView3.Refresh();
		}

		private void TrustAction()
		{
			List<int> list = new List<int>();
			List<int> list2 = new List<int>();
			new List<int>();
			list2.Add(0);
			int num = 0;
			for (int i = 0; i < this.dataGridView3.Rows.Count; i++)
			{
				if ((bool)this.dataGridView3.Rows[i].Cells[2].EditedFormattedValue)
				{
					list.Add(i);
				}
			}
			int num2 = 0;
			while (num2 < this.dataGridView3.Rows.Count && num2 != this.dataGridView3.Rows.Count - 2)
			{
				if (this.dataGridView3.Rows[num].Cells[0].EditedFormattedValue.Equals(this.dataGridView3.Rows[num2].Cells[0].EditedFormattedValue))
				{
					num++;
				}
				else
				{
					num++;
					list2.Add(num);
				}
				num2++;
			}
			for (int j = 0; j < list.Count; j++)
			{
				if (list2.Contains(list[j]))
				{
					this.dataGridView3.Rows[list[j]].Cells[0].Style.ForeColor = this.dataGridView3.Rows[list[j]].Cells[0].Style.BackColor;
				}
				else
				{
					this.dataGridView3.Rows[list[j]].Cells[0].Style.ForeColor = this.dataGridView3.Rows[list[j]].Cells[0].Style.BackColor;
				}
			}
			int num3 = 0;
			for (int k = 0; k < list.Count; k++)
			{
				this.m_RoomTable.Rows.Remove(this.m_RoomTable.Rows[list[k]]);
				if (list.Count > k + 1)
				{
					num3++;
					list[k + 1] = list[k + 1] - num3;
				}
			}
			foreach (KeyValuePair<int, List<int>> keyValuePair in this.m_RowRoomId)
			{
				int item = keyValuePair.Key - 1;
				foreach (int item2 in keyValuePair.Value)
				{
					if (list.Contains(item))
					{
						this.TrustElems.Add(item2);
					}
				}
			}
			this.GetTrustDoorPackers();
		}

		private void RefreshBtn_Click(object sender, EventArgs e)
		{
			this.BindWindowDoorData(this.lstDoorAndWindow);
		}

		private void CloseBtn_Click(object sender, EventArgs e)
		{
			base.Close();
		}

		private void dataGridView3_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
		{
			this.m_strReplaceOrder = "doubleClick";
			this.m_bIfContinue = true;
			this.m_bIfBreak = false;
			this.m_bIfManuEsc = false;
			this.SendEscMessageToRevitAndClearSelect();
			this.m_useBeforeCotinueMethod = new FireProofGradeForm.BeforeContinueMethod(this.LocationMethod);
		}

		private bool InitFamilyLibDoorWins()
		{
			try
			{
				SqliteDatabase sqliteDB = FamilyLibDatabase.GetSqliteDB(SubjectType.Architecture, this.m_cmdData.Application.Application.VersionNumber);
				DbCategory dbCategory = sqliteDB.CategoryTable["防火门"];
				this.m_lstFamilyLibDoors = dbCategory.GetAllFamilies(true, CheckType.All);
				DbCategory dbCategory2 = sqliteDB.CategoryTable["防火卷帘门"];
				this.m_lstFamilyLibDoorsRolling = dbCategory2.GetAllFamilies(true, CheckType.All);
				DbCategory dbCategory3 = sqliteDB.CategoryTable["防火窗"];
				this.m_lstFamilyLibWins = dbCategory3.GetAllFamilies(true, CheckType.All);
			}
			catch
			{
				return false;
			}
			return true;
		}

		private void ComponentBtn_Click(object sender, EventArgs e)
		{
			this.m_strReplaceOrder = "DoorOrWindowReplace";
			this.ReplaceAction();
			this.m_bIfContinue = true;
			this.m_bIfBreak = false;
			this.m_bIfManuEsc = false;
			this.SendEscMessageToRevitAndClearSelect();
			this.m_useBeforeCotinueMethod = new FireProofGradeForm.BeforeContinueMethod(this.ReplaceComponent);
		}

		private void ReplaceAction()
		{
			ReplaceFamilyinstanceForm replaceFamilyinstanceForm = new ReplaceFamilyinstanceForm(this.m_cmdData);
			replaceFamilyinstanceForm.m_lstFamilyLibDoors = this.m_lstFamilyLibDoors;
			replaceFamilyinstanceForm.m_lstFamilyLibDoorsRolling = this.m_lstFamilyLibDoorsRolling;
			replaceFamilyinstanceForm.m_lstFamilyLibWins = this.m_lstFamilyLibWins;
			if (replaceFamilyinstanceForm.ShowDialog() == DialogResult.OK)
			{
				this.m_strDoorClassAFiName = replaceFamilyinstanceForm.FireDoorClassAFiName;
				this.m_strDoorSuperFiName = replaceFamilyinstanceForm.FireDoorSuperFiName;
				this.m_strWindowFiName = replaceFamilyinstanceForm.FireWindowClassAFiName;
				this.ReplaceFamilyInstance();
			}
		}

		private void ReplaceFrontRoomDoor()
		{
			FrontRoomDoorReplaceForm frontRoomDoorReplaceForm = new FrontRoomDoorReplaceForm(this.m_cmdData);
			frontRoomDoorReplaceForm.m_lstFamilyLibDoors = this.m_lstFamilyLibDoors;
			frontRoomDoorReplaceForm.m_lstFamilyLibDoorsRolling = this.m_lstFamilyLibDoorsRolling;
			if (frontRoomDoorReplaceForm.ShowDialog() == DialogResult.OK)
			{
				this.m_strDoorClassAFiName = frontRoomDoorReplaceForm.FireDoorClassAFiName;
				this.m_strDoorSuperFiName = frontRoomDoorReplaceForm.FireDoorSuperFiName;
				this.ReplaceRoomDoorAction();
			}
		}

		private void GetTrustDoorPackers()
		{
			List<AdapteDoorResultPakcer> list = new List<AdapteDoorResultPakcer>();
			foreach (AdapteDoorResultPakcer adapteDoorResultPakcer in this.lstUseDoorPackers)
			{
				if (this.TrustElems.Contains(adapteDoorResultPakcer.ThisElement.Id.IntegerValue))
				{
					list.Add(adapteDoorResultPakcer);
				}
			}
			for (int i = 0; i < list.Count; i++)
			{
				this.useRoom.Add(list[i].UseICloseCurveAnalays.GetThisElement());
				if (this.useRoom != null)
				{
					InsertDoor insertDoor = new InsertDoor();
					if (this.useRoom[i] is Room)
					{
						insertDoor.m_FrontRoomName = (this.useRoom[i] as Room).Name;
						insertDoor.m_FrontRoomArea = (this.useRoom[i] as Room).Area;
					}
					else if (this.useRoom[i] is FilledRegion)
					{
						insertDoor.m_FrontRoomName = (this.useRoom[i] as FilledRegion).Name;
						double tmpArea = (this.useRoom[i] as FilledRegion).get_Parameter(BuiltInParameter.HOST_AREA_COMPUTED).AsDouble();
						insertDoor.m_FrontRoomArea = YJKRoomInspection.Utiltiy.Utility.ChangeAreaByUnit(tmpArea);
					}
					this.lsttmpdata.Add(insertDoor);
				}
			}
			InsertDataToRoom.WriteToElement(this.useRoom, YJKRoomInspection.Properties.Resources.DoorGuid, this.lsttmpdata);
		}

		private void FireProofGradeForm_FormClosed(object sender, FormClosedEventArgs e)
		{
			List<int> notDeleteRoom = YJKRoomInspection.Utiltiy.Utility.GetNotDeleteRoom(this.document);
			ElementPackerManger.TryDeletedAddedRoom(this.document, notDeleteRoom);
		}

		private void dataGridView3_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e)
		{
			int num = 0;
			foreach (KeyValuePair<int, List<AdapteDoorResultPakcer>> keyValuePair in this.m_dicFrontRoomDoor)
			{
				using (List<AdapteDoorResultPakcer>.Enumerator enumerator2 = keyValuePair.Value.GetEnumerator())
				{
					while (enumerator2.MoveNext())
					{
						if (enumerator2.Current.UseRevitLinkInstance != null)
						{
							this.dataGridView3.Rows[num].Cells["DoorName"].Style.BackColor = System.Drawing.Color.LightGray;
						}
						num++;
					}
				}
			}
		}

		private void dataGridView1_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e)
		{
			int num = 0;
			foreach (KeyValuePair<int, List<AdapteDoorResultPakcer>> keyValuePair in this.m_dicWindowDoor)
			{
				using (List<AdapteDoorResultPakcer>.Enumerator enumerator2 = keyValuePair.Value.GetEnumerator())
				{
					while (enumerator2.MoveNext())
					{
						if (enumerator2.Current.BIsLinkElement)
						{
							this.dataGridView1.Rows[num].Cells["WinDoorName"].Style.BackColor = System.Drawing.Color.LightGray;
						}
						num++;
					}
				}
			}
		}

		private void dataGridView2_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e)
		{
			int num = 0;
			foreach (KeyValuePair<int, List<AdapteDoorResultPakcer>> keyValuePair in this.m_dicWallDoor)
			{
				using (List<AdapteDoorResultPakcer>.Enumerator enumerator2 = keyValuePair.Value.GetEnumerator())
				{
					while (enumerator2.MoveNext())
					{
						if (enumerator2.Current.BIsLinkElement)
						{
							this.dataGridView2.Rows[num].Cells["WallDoorName"].Style.BackColor = System.Drawing.Color.LightGray;
						}
						num++;
					}
				}
			}
		}

		private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
		{
			this.m_strReplaceOrder = "doubleClick";
			this.m_bIfContinue = true;
			this.m_bIfBreak = false;
			this.m_bIfManuEsc = false;
			this.SendEscMessageToRevitAndClearSelect();
			this.m_useBeforeCotinueMethod = new FireProofGradeForm.BeforeContinueMethod(this.WinLocationMethod);
		}

		private void dataGridView2_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
		{
			this.m_strReplaceOrder = "doubleClick";
			this.m_bIfContinue = true;
			this.m_bIfBreak = false;
			this.m_bIfManuEsc = false;
			this.SendEscMessageToRevitAndClearSelect();
			this.m_useBeforeCotinueMethod = new FireProofGradeForm.BeforeContinueMethod(this.WallLocationMethod);
		}

		private void LocationMethod()
		{
			DataGridViewCell dataGridViewCell = null;
			IEnumerator enumerator = this.dataGridView3.SelectedCells.GetEnumerator();
			{
				if (enumerator.MoveNext())
				{
					dataGridViewCell = (DataGridViewCell)enumerator.Current;
				}
			}
			List<int> list = new List<int>();
			if (dataGridViewCell == null || dataGridViewCell.RowIndex == -1)
			{
				return;
			}
			if (dataGridViewCell.ColumnIndex != -1 || dataGridViewCell.RowIndex != -1)
			{
				this.m_RowRoomId.TryGetValue(dataGridViewCell.RowIndex + 1, out list);
			}
			if (list == null)
			{
				return;
			}
			Selection selection = this.uidoc.Selection;
			List<Element> list2 = new List<Element>();
			ElementSet elementSet = new ElementSet();
			ElementId elementId = null;
			ElementId elementId2 = new ElementId(list[0]);
			Element element = this.document.GetElement(elementId2);
			if (element is FamilyInstance)
			{
				elementId = element.LevelId;
				list2.Add(element);
				elementSet.Insert(element);
			}
			foreach (ViewPlan viewPlan in this.lstviewList)
			{
				int integerValue = elementId.IntegerValue;
				if (viewPlan.GenLevel != null && viewPlan.GenLevel.Id.IntegerValue == integerValue)
				{
					this.uidoc.ActiveView = viewPlan;
					break;
				}
			}
			this.uidoc.ShowElements(elementSet);
			RevitVersionFuncs.SetSelection(selection, list2);
			this.uidoc.RefreshActiveView();
		}

		private void WinLocationMethod()
		{
			DataGridViewCell dataGridViewCell = null;
			IEnumerator enumerator = this.dataGridView1.SelectedCells.GetEnumerator();
			{
				if (enumerator.MoveNext())
				{
					dataGridViewCell = (DataGridViewCell)enumerator.Current;
				}
			}
			List<int> list = new List<int>();
			if (dataGridViewCell == null || dataGridViewCell.RowIndex == -1)
			{
				return;
			}
			if (dataGridViewCell.ColumnIndex != -1 || dataGridViewCell.RowIndex != -1)
			{
				this.m_RowWinId.TryGetValue(dataGridViewCell.RowIndex + 1, out list);
			}
			if (list == null)
			{
				return;
			}
			Selection selection = this.uidoc.Selection;
			List<Element> list2 = new List<Element>();
			ElementSet elementSet = new ElementSet();
			ElementId elementId = null;
			ElementId elementId2 = new ElementId(list[0]);
			Element element = this.document.GetElement(elementId2);
			if (element is FamilyInstance)
			{
				elementId = element.LevelId;
				list2.Add(element);
				elementSet.Insert(element);
			}
			foreach (ViewPlan viewPlan in this.lstviewList)
			{
				int integerValue = elementId.IntegerValue;
				if (viewPlan.GenLevel != null && viewPlan.GenLevel.Id.IntegerValue == integerValue)
				{
					this.uidoc.ActiveView = viewPlan;
					break;
				}
			}
			this.uidoc.ShowElements(elementSet);
			RevitVersionFuncs.SetSelection(selection, list2);
			this.uidoc.RefreshActiveView();
		}

		private void WallLocationMethod()
		{
			DataGridViewCell dataGridViewCell = null;
			IEnumerator enumerator = this.dataGridView2.SelectedCells.GetEnumerator();
			{
				if (enumerator.MoveNext())
				{
					dataGridViewCell = (DataGridViewCell)enumerator.Current;
				}
			}
			List<int> list = new List<int>();
			if (dataGridViewCell == null || dataGridViewCell.RowIndex == -1)
			{
				return;
			}
			if (dataGridViewCell.ColumnIndex != -1 || dataGridViewCell.RowIndex != -1)
			{
				this.m_RowWallId.TryGetValue(dataGridViewCell.RowIndex + 1, out list);
			}
			if (list == null)
			{
				return;
			}
			Selection selection = this.uidoc.Selection;
			List<Element> list2 = new List<Element>();
			ElementSet elementSet = new ElementSet();
			ElementId elementId = null;
			ElementId elementId2 = new ElementId(list[0]);
			Element element = this.document.GetElement(elementId2);
			if (element is Wall)
			{
				elementId = element.LevelId;
				list2.Add(element);
				elementSet.Insert(element);
			}
			foreach (ViewPlan viewPlan in this.lstviewList)
			{
				int integerValue = elementId.IntegerValue;
				if (viewPlan.GenLevel != null && viewPlan.GenLevel.Id.IntegerValue == integerValue)
				{
					this.uidoc.ActiveView = viewPlan;
					break;
				}
			}
			this.uidoc.ShowElements(elementSet);
			RevitVersionFuncs.SetSelection(selection, list2);
			this.uidoc.RefreshActiveView();
		}

		private void WallCloseBtn_Click(object sender, EventArgs e)
		{
			this.m_strReplaceOrder = "CloseWall";
			this.m_bIfContinue = true;
			this.m_bIfBreak = false;
			this.m_bIfManuEsc = false;
			this.SendEscMessageToRevitAndClearSelect();
			this.m_useBeforeCotinueMethod = new FireProofGradeForm.BeforeContinueMethod(this.CloseWalls);
		}

		private void RoomReplaceBtn_Click(object sender, EventArgs e)
		{
			this.m_strReplaceOrder = "FrontRoomDoorReplace";
			this.ReplaceFrontRoomDoor();
			this.m_bIfContinue = true;
			this.m_bIfBreak = false;
			this.m_bIfManuEsc = false;
			this.SendEscMessageToRevitAndClearSelect();
			this.m_useBeforeCotinueMethod = new FireProofGradeForm.BeforeContinueMethod(this.ReplaceFrontRoomComponent);
		}

		private void button3_Click(object sender, EventArgs e)
		{
			base.Close();
		}

		private void RoomCloseBtn_Click(object sender, EventArgs e)
		{
			base.Close();
		}

		private void WallRefreshBtn_Click(object sender, EventArgs e)
		{
			List<AdapteDoorResultPakcer> oldDoorsResult = new List<AdapteDoorResultPakcer>();
			List<AdapteDoorResultPakcer> list = new List<AdapteDoorResultPakcer>();
			oldDoorsResult = BaseManger.GetCheckResults(this.lstUseViewPlan);
			list = this.GetWall(oldDoorsResult);
			this.BindWallDoorData(list);
		}

		private void RoomRefreshBtn_Click(object sender, EventArgs e)
		{
			this.BindFrontRoomDoorData(this.lstIsNotLinkDoor);
		}

		protected override bool ProcessKeyEventArgs(ref Message m)
		{
			int num = 256;
			int num2 = 27;
			if (m.Msg == num && m.WParam.ToInt32() == num2)
			{
				base.Close();
			}
			return base.ProcessKeyEventArgs(ref m);
		}

		public bool IfBreak
		{
			get
			{
				return this.m_bIfBreak;
			}
		}

		public bool IfContinue
		{
			get
			{
				return this.m_bIfContinue;
			}
		}

		public bool IfManualEsc
		{
			get
			{
				return this.m_bIfManuEsc;
			}
		}

		public void CloseForm()
		{
			if (!base.IsDisposed)
			{
				base.Close();
			}
		}

		public void ResetContinueBreak()
		{
			this.m_bIfContinue = false;
			this.m_bIfBreak = true;
			this.m_bIfManuEsc = true;
		}

		public void SendEscMessageToRevitAndClearSelect()
		{
			this.m_useBeforeCotinueMethod = null;
			RevitVersionFuncs.ClearSelection(this.uidoc.Selection);
			YJKInspectModelFunc.Utility.SendEscToHandle(this.RevitHandle);
		}

		public void ShowForm(IWin32Window parentForm = null)
		{
			if (this.RevitHandle != null)
			{
				base.Show(this.RevitHandle);
				return;
			}
			base.Show();
		}

		public void DoBeforeContinue()
		{
			if (this.m_useBeforeCotinueMethod != null)
			{
				this.m_useBeforeCotinueMethod();
			}
		}

		public void ReplaceComponent()
		{
			BaseReplacer.ReplaceFamilyForFamilyInstance(this.lstDoorAndWindow, this.useKindAndNames, "OutLine");
		}

		public void ReplaceFrontRoomComponent()
		{
			BaseReplacer.ReplaceFamilyForFamilyInstance(this.lstIsNotLinkDoor, this.useKindAndNames, "FrontRoom");
		}

		public void CloseWalls()
		{
			BaseManger.MakeCloseWalls(this.lstUseViewPlan);
		}

		public string strFormCaption;

		private ExternalCommandData m_cmdData;

		public UIDocument uidoc;

		private Document document;

		private Dictionary<int, List<int>> m_RowRoomId = new Dictionary<int, List<int>>();

		private Dictionary<int, List<int>> m_RowWinId = new Dictionary<int, List<int>>();

		private Dictionary<int, List<int>> m_RowWallId = new Dictionary<int, List<int>>();

		private DataGridViewCellStyle m_RowStyleAlternate;

		private List<AdapteDoorResultPakcer> lstUseDoorPackers = new List<AdapteDoorResultPakcer>();

		private List<AdapteDoorResultPakcer> lstAdapteDoorPackers = new List<AdapteDoorResultPakcer>();

		private string m_strDoorClassAFiName;

		private string m_strDoorSuperFiName;

		private string m_strWindowFiName;

		private List<DbFamily> m_lstFamilyLibDoors;

		private List<DbFamily> m_lstFamilyLibDoorsRolling;

		private List<DbFamily> m_lstFamilyLibWins;

		private List<int> TrustElems = new List<int>();

		private List<ViewPlan> lstviewList = new List<ViewPlan>();

		public List<ViewPlan> lstUseViewPlan = new List<ViewPlan>();

		private Dictionary<int, List<AdapteDoorResultPakcer>> m_dicFrontRoomDoor = new Dictionary<int, List<AdapteDoorResultPakcer>>();

		private Dictionary<int, List<AdapteDoorResultPakcer>> m_dicWindowDoor = new Dictionary<int, List<AdapteDoorResultPakcer>>();

		private Dictionary<int, List<AdapteDoorResultPakcer>> m_dicWallDoor = new Dictionary<int, List<AdapteDoorResultPakcer>>();

		public List<AdapteDoorResultPakcer> lstIsNotLinkDoor = new List<AdapteDoorResultPakcer>();

		public List<AdapteDoorResultPakcer> lstDoorAndWindow = new List<AdapteDoorResultPakcer>();

		public Dictionary<string, string> useKindAndNames = new Dictionary<string, string>();

		public string m_strReplaceOrder = " ";

		private DataTable m_RoomTable;

		private IWin32Window m_revitHandle;

		private FireProofGradeForm.BeforeContinueMethod m_useBeforeCotinueMethod;

		private List<AdapteRoomResulePacker> m_inputValue = new List<AdapteRoomResulePacker>();

		private ViewPlan m_frontViewPlan;

		public List<Element> useRoom = new List<Element>();

		public List<InsertDoor> lsttmpdata = new List<InsertDoor>();

		private delegate void BeforeContinueMethod();
	}
}
